package cn.azzhu.crud.controller;

import cn.azzhu.crud.bean.User;
import cn.azzhu.crud.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;

/**
 * @author azzhu
 * @create 2020-08-17 16:08:47
 */
@Controller
@RequestMapping("user")
//@RestController
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("list")
    public String list(Map<String,Object> map) {
        final List<User> list = userService.getAll();
        map.put("list",list);
        return "user/list";
    }

    @GetMapping("del/{id}")
    public String del(@PathVariable("id") Integer id) {
        userService.delById(id);
        return "redirect:/user/list";
    }

    @GetMapping("jsonlist")
    @ResponseBody
    //@CrossOrigin
    public Object jsonist(Map<String,Object> map) {
        final List<User> list = userService.getAll();
       // int a = 10/0;
        return list;
    }
}
